﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T7practice1
{
    class DBHelper
    {
        public static string constr = "server=.;database=Games;Integrated Security=true";

        public static DataTable Select(string sql)
        {
            
            //1.创建数据库连接对象Connection
            SqlConnection conn = new SqlConnection(constr);
            //2.创建数据适配对象DataAdapter
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            conn.Open();
            //3.创建数据集DataSet或DataTable对象，用于缓存数据
            DataTable dt = new DataTable();
            //4.调用DataAdapter对象的Fill()方法填充DataTable对象
            da.Fill(dt);
            //5.绑定数据源到ListView或DataGridView等数据控件上
            return dt;
        }
    }
}
